﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BFlatCompile.Nodes
{
	internal class NativeCodeInsertion : Expression
	{
		private static readonly Expression[] EMPTY_ARGS = new Expression[0];
		public string ID { get; private set; }
		public Expression[] Args { get; private set; }

		public NativeCodeInsertion(string id, IList<Expression> args)
		{
			this.ID = id;
			this.Args = args == null ? EMPTY_ARGS : args.ToArray();
		}

		public static NativeCodeInsertion ParseNativeCodeInsertion(Tokens tokens)
		{
			tokens.PopExpected("@");
			string id = tokens.PopIdentifier();

			Expression[] args = null;
			if (tokens.PopIfPresent("("))
			{

				args = Expression.ParseCommaList(tokens);
				tokens.PopExpected(")");
			}

			return new NativeCodeInsertion(id, args);
		}

		public override void ResolveCode(Class c, Dictionary<object, object> parents)
		{
			// do nothing
		}

		public override void ResolveClassToThis(Class c)
		{
			// do nothing
		}
	}
}
